//
//  PTRecorderSetValueController.m
//  PocketTutor
//
//  Created by yate1996 on 15/6/10.
//  Copyright (c) 2015年 yate1996. All rights reserved.
//

#import "PTRecorderSetValueController.h"
#import "CDPStarEvaluation.h"
#import "MeItem.h"
#import "PTTextView.h"
@interface PTRecorderSetValueController ()<UIAlertViewDelegate>{
    
    CDPStarEvaluation *_starEvaluation;//星形评价
    
}

@end

@implementation PTRecorderSetValueController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    [self setupView];
    
    [self setupSetValue];
    
    
}

- (void)setMeItem:(MeItem *)meItem
{
    
    _meItem = meItem;
    
}

-(void)setupView
{
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"Comment";
    
    
    UILabel *teacherNameLabel = [[UILabel alloc]init];
    teacherNameLabel.font = PTRecorderFont15;
    [self.view addSubview:teacherNameLabel];
    self.teacherNameLabel = teacherNameLabel;
    
    UIImageView *teacherIconView = [[UIImageView alloc]init];
    [self.view addSubview:teacherIconView];
    self.teacherIconView = teacherIconView;
    self.teacherIconView.image = [UIImage imageNamed:self.meItem.teacherIcon];
    

    
    CGFloat iconX = 1.5 * PTRecorderCellInset;
    CGFloat iconY = 1.5 * PTRecorderCellInset + 64;
    CGFloat iconW = 60;
    CGFloat iconH = 60;
    self.teacherIconView.frame = CGRectMake(iconX, iconY, iconW, iconH);
    
    CGFloat titleX = CGRectGetMaxX(self.teacherIconView.frame) + 15;
    NSMutableDictionary *textAttr = [NSMutableDictionary dictionary];
    textAttr[NSFontAttributeName] = PTRecorderFont15;
    CGSize titleSize = [self.meItem.teacherName sizeWithAttributes:textAttr];
    self.teacherNameLabel.frame = (CGRect){{titleX,0},titleSize};
    self.teacherNameLabel.centerY = self.teacherIconView.centerY;
    self.teacherNameLabel.text = self.meItem.teacherName;

    PTTextView *myComment = [[PTTextView alloc]initWithFrame:CGRectMake(iconX, CGRectGetMaxY(self.teacherIconView.frame) + 4 * PTRecorderCellMargin + 40 , 290, 100)];

    [myComment setPlacehoder:@"Say something here ……"];
    [myComment.layer setBorderColor: [PTColor(230, 230, 230, 1.0) CGColor]];
    [myComment.layer setBorderWidth: 1.0];
    [myComment.layer setMasksToBounds:YES];
    [self.view addSubview:myComment];
    self.myComment = myComment;
    
}

-(void)setupSetValue
{
    
    //CDPStarEvaluation星形评价
    _starEvaluation=[[CDPStarEvaluation alloc] initWithFrame:CGRectMake(PTRecorderCellInset,CGRectGetMaxY(self.teacherIconView.frame) + 2 * PTRecorderCellMargin ,200,40.1) onTheView:self.view];
    
    
    //提交评论
    UIButton *submitCommentButton=[[UIButton alloc] initWithFrame:CGRectMake(1.5 * PTRecorderCellInset,CGRectGetMaxY(self.teacherIconView.frame) + 200 ,290,self.view.bounds.size.height*0.07042254)];
    submitCommentButton.backgroundColor=[UIColor colorWithRed:232/255.0 green:84/255.0 blue:88/255.0 alpha:1];
    [submitCommentButton setTitle:@"Submit" forState:UIControlStateNormal];
    [submitCommentButton addTarget:self action:@selector(submitCommentClick) forControlEvents:UIControlEventTouchUpInside];
    submitCommentButton.titleLabel.font=[UIFont boldSystemFontOfSize:16];
    [self.view addSubview:submitCommentButton];
}

#pragma mark 点击事件
//提交评论
-(void)submitCommentClick{
    if (_starEvaluation.width > 0) {
        UIAlertView *alertView=[[UIAlertView alloc] initWithTitle:@"提交结果" message:[NSString stringWithFormat:@"分数:%.1f",_starEvaluation.width*5] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
        alertView.delegate = self;
        self.block(_starEvaluation.width*5,self.myComment.text);
        [alertView show];
    }

    
}


-(void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
    [self.navigationController popViewControllerAnimated:YES];
}
@end
